package com.jzg.jcptadmin.ui;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.jzg.jcptadmin.R;
import com.jzg.jcptadmin.Utils.MD5Utils;
import com.jzg.jcptadmin.Utils.MyToast;
import com.jzg.jcptadmin.app.AppManager;
import com.jzg.jcptadmin.base.BaseActivity;
import com.jzg.jcptadmin.constant.Constant;
import com.jzg.jcptadmin.data.DataManager;
import com.jzg.jcptadmin.data.local.LocalData;
import com.jzg.jcptadmin.data.vo.Canpei;
import com.jzg.jcptadmin.data.vo.RepairBean;
import com.jzg.jcptadmin.data.vo.SuccessValuationData;
import com.jzg.jcptadmin.presenter.OperationEvaluationPresenter;
import com.jzg.jcptadmin.viewinterface.OperationEvaluationInterface;

import java.util.HashMap;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class SubmitInActivity extends BaseActivity implements View.OnClickListener, OperationEvaluationInterface {


    @Bind(R.id.title_content)
    TextView titleContent;
    @Bind(R.id.title_return)
    ImageView titleReturn;
    @Bind(R.id.title)
    TextView title;
    @Bind(R.id.close_car)
    TextView closeCar;
    @Bind(R.id.sale_car)
    TextView saleCar;
    @Bind(R.id.shape)
    LinearLayout shape;
    @Bind(R.id.middle_position)
    TextView middlePosition;
    @Bind(R.id.value_close_car)
    TextView valueCloseCar;
    @Bind(R.id.value_sale_car)
    TextView valueSaleCar;
    @Bind(R.id.change)
    Button change;
    @Bind(R.id.submit)
    Button submit;

    SuccessValuationData result;
    private String buy_money;
    private String sale_money;
    private OperationEvaluationPresenter operationEvaluationPresenter;
    EvaluationActivity.SerializableMap serializableMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_submit_in);
        ButterKnife.bind(this);
        titleContent.setText("提交确认");
        result = getIntent().getParcelableExtra("result");
//        serializableMap = (EvaluationActivity.SerializableMap) getIntent().getExtras().get("map");
//        serializableMap=getIntent().getParcelableExtra("map");
//        serializableMap = (EvaluationActivity.SerializableMap) getIntent().getExtras().get("map");
//        getIntent().getExtras().get("");
//        serializableMap=getIntent().getStringExtra("map");
        // 建议收车价
        closeCar.setText("建议收车价：" + result.getJZGPrice().getJZGAssessmentPrice() + "万元");
        //建议售车价
        saleCar.setText("建议售车价：" + result.getJZGPrice().getJZGSalePrice() + "万元");
        //车商收车价格
        buy_money = getIntent().getStringExtra("buy_money");
        valueCloseCar.setText("您评估的收车价：" + buy_money + "万元 ");
        ////车商售车价格
        sale_money = getIntent().getStringExtra("sale_money");
        valueSaleCar.setText("您评估的售车价：" + sale_money + "万元 ");
        operationEvaluationPresenter = new OperationEvaluationPresenter(DataManager.getInstance());
        operationEvaluationPresenter.attachView(this);
    }

    @OnClick({R.id.change, R.id.title_return, R.id.submit})
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            //修改价格
            case R.id.change:
                finish();
                break;
            //确认提交
            case R.id.submit:
                showDialog();
                operationEvaluationPresenter.OperationEvaluationData();
                break;
            case R.id.title_return:
                finish();
                break;
        }
    }

    //
    @Override
    public void showresult(SuccessValuationData result) {
        dismissDialog();
        LocalData.isRefresh = true;
        finish();
        AppManager.getAppManager().finishActivity(EvaluationActivity.class);
        AppManager.getAppManager().finishActivity(FastOnlineCheckActivity1.class);
        MyToast.showShort("成功提交评估信息");
    }

    @Override
    public void showError(String error) {
        dismissDialog();
        MyToast.showLong(Constant.errr_net);
    }

    @Override
    public void getRepairSuccess(RepairBean repairBean) {
        //TODO 建议用新的OperationEvaluationInterface
    }

    /**
     * 获取评估参数
     *
     * @return
     */
    @Override
    public Map<String, String> getEvaluationParams() {
        Map<String, String> params = new HashMap<String, String>();
        params.put("tokenid", "6");
        params.put("type", "pinggu");
        params.put("taskid", getIntent().getStringExtra("taskid"));

        params.put("appraiseprice", getIntent().getStringExtra("appraiseprice"));//收车价
        params.put("appraisedes", getIntent().getStringExtra("appraisedes"));
        params.put("SalePrice", getIntent().getStringExtra("SalePrice"));

        params.put("isConfirmSubmit", 1 + "");//评估误差较大时，是否确认提交 1是 0否

        params.put("JZGAssessmentPrice", result.getJZGPrice().getJZGAssessmentPrice() + "");
        params.put("JZGSalePrice", result.getJZGPrice().getJZGSalePrice() + "");


        params.put("userId", getIntent().getStringExtra("userId"));
        params.put("MakeId", getIntent().getStringExtra("MakeId"));
        params.put("ModelId", getIntent().getStringExtra("ModelId"));
        params.put("StyleId", getIntent().getStringExtra("StyleId"));
        params.put("CityId", getIntent().getStringExtra("CityId"));
        params.put("RegDate", getIntent().getStringExtra("RegDate"));//登记日期
        params.put("Mileage", getIntent().getStringExtra("Mileage"));///表显里程

        params.put("makeNumber", getIntent().getStringExtra("makeNumber"));//品牌型号
        params.put("carLicence", getIntent().getStringExtra("carLicence"));//车牌号
        params.put("service", getIntent().getStringExtra("service"));//使用性质
        params.put("carColor", getIntent().getStringExtra("carColor"));//车身颜色
        params.put("engineNum", getIntent().getStringExtra("engineNum"));//发动机号
        params.put("mPrice", getIntent().getStringExtra("mPrice"));//厂商指导价
        params.put("fuel", getIntent().getStringExtra("fuel"));//燃料
        params.put("exhaust", getIntent().getStringExtra("exhaust"));//排气量
        params.put("carType", getIntent().getStringExtra("carType"));//车辆类型
        params.put("tranType", getIntent().getStringExtra("tranType"));//变速器
        params.put("seating", getIntent().getStringExtra("seating"));//载客人数
        params.put("productionTime", getIntent().getStringExtra("productionTime"));//出厂日期
        params.put("VIN", getIntent().getStringExtra("VIN"));//vin

        Map<String, Object> maps = new HashMap<>();
        maps.putAll(params);
        params.put("sign", MD5Utils.getMD5Sign(maps));
        return params;
    }

    @Override
    public void showCanPei(Canpei result) {

    }

    @Override
    public Map<String, String> getCanpeiParams(String styleID) {
        return null;
    }


    @Override
    public void showDialog() {

    }

    @Override
    public void dismissDialog() {

    }
}
